package org.example.bookstore.mapper;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.bookstore.custom.ResultVO;
import org.example.bookstore.pojo.DO.Comment;
import org.example.bookstore.pojo.DTO.CommentUser;

import java.util.List;

@Mapper
public interface CommentMapper {
    /*
     * 评论添加
     * */
    @Insert("INSERT INTO comments ( bookId, userId, rating, content, commentLikeCount, toCommentId, commentTime, updateTime) " +
            "VALUES ( #{bookId}, #{userId}, #{rating}, #{content}, #{commentLikeCount}, #{toCommentId}, #{commentTime}, #{updateTime})")
    Integer addComment(Comment comment);


    List<CommentUser> getCommentListById(Integer id);

    /*
     * 根据书本id评论查询总数
     * */
    @Select("SELECT COUNT(*) from comments where bookId=#{id}")
    int getCommentSumById(Integer id);

    /*
     * 根据评论id删除评论
     * */
    @Delete("delete from comments where id=#{id}")
    int deleteCommentById(Integer id);
}
